home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form ValidS1
- BorderStyle = 3 'Fixed Dialog
- Caption = "Validate Control Sample"
- ClientHeight = 5985
- ClientLeft = 975
- ClientTop = 1635
- ClientWidth = 6645
- ControlBox = 0 'False
- Height = 6390
- Left = 915
- LinkTopic = "Form1"
- LockControls = -1 'True
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 5985
- ScaleWidth = 6645
- ShowInTaskbar = 0 'False
- Top = 1290
- Width = 6765
- Begin VB.HScrollBar HScroll1
- Height = 285
- Left = 450
- TabIndex = 20
- Top = 4305
- Width = 5385
- End
- Begin VB.VScrollBar VScroll1
- Height = 1245
- Left = 5850
- TabIndex = 19
- Top = 4560
- Width = 300
- End
- Begin VB.TextBox txtFax
- Height = 285
- Left = 1200
- TabIndex = 7
- Top = 3000
- Width = 2775
- End
- Begin VB.TextBox txtPhone
- Height = 285
- Left = 1200
- TabIndex = 6
- Top = 2640
- Width = 2775
- End
- Begin VB.TextBox txtZipCode
- Height = 285
- Left = 1200
- TabIndex = 5
- Top = 2040
- Width = 1455
- End
- Begin VB.TextBox txtCityState
- Height = 285
- Left = 1200
- TabIndex = 4
- Top = 1680
- Width = 2775
- End
- Begin VB.TextBox txtAddress2
- Height = 285
- Left = 1200
- TabIndex = 3
- Top = 1320
- Width = 2775
- End
- Begin VB.TextBox txtAddress
- Height = 285
- Left = 1200
- TabIndex = 2
- Top = 960
- Width = 2775
- End
- Begin VB.TextBox txtCompany
- Height = 285
- Left = 1200
- TabIndex = 1
- Top = 600
- Width = 2775
- End
- Begin VB.TextBox txtName
- Height = 285
- Left = 1200
- TabIndex = 0
- Top = 240
- Width = 2775
- End
- Begin VB.CommandButton btnCancel
- Cancel = -1 'True
- Caption = "Cancel"
- Height = 375
- Left = 4680
- TabIndex = 9
- Top = 720
- Width = 1695
- End
- Begin VB.CommandButton btnOK
- Caption = "OK"
- Default = -1 'True
- Height = 375
- Left = 4680
- TabIndex = 8
- Top = 240
- Width = 1695
- End
- Begin VB.Label Label9
- Caption = $"VALIDS1.frx":0000
- Height = 1095
- Left = 480
- TabIndex = 18
- Top = 4605
- Width = 5220
- End
- Begin VB.Label Label8
- Caption = $"VALIDS1.frx":0158
- Height = 720
- Left = 480
- TabIndex = 17
- Top = 3600
- Width = 5655
- End
- Begin VB.Label Label7
- Caption = "Fax:"
- Height = 255
- Left = 240
- TabIndex = 16
- Top = 3000
- Width = 855
- End
- Begin VB.Label Label6
- Caption = "Phone:"
- Height = 255
- Left = 240
- TabIndex = 15
- Top = 2640
- Width = 855
- End
- Begin VB.Label Label5
- Caption = "Zip Code:"
- Height = 255
- Left = 240
- TabIndex = 14
- Top = 2040
- Width = 855
- End
- Begin VB.Label Label4
- Caption = "City, State:"
- Height = 255
- Left = 240
- TabIndex = 13
- Top = 1680
- Width = 855
- End
- Begin VB.Label Label3
- Caption = "Address:"
- Height = 255
- Left = 240
- TabIndex = 12
- Top = 960
- Width = 855
- End
- Begin VB.Label Label2
- Caption = "Company:"
- Height = 255
- Left = 240
- TabIndex = 11
- Top = 600
- Width = 855
- End
- Begin VB.Label Label1
- Caption = "Name:"
- Height = 255
- Left = 240
- TabIndex = 10
- Top = 240
- Width = 855
- End
- Begin MabryValidate.Validate Validate1
- Left = 5880
- Top = 1200
- _Version = 65536
- _ExtentX = 847
- _ExtentY = 847
- _StockProps = 64
- End
- Attribute VB_Name = "ValidS1"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Private m_wasValidating As Control
- Private Sub btnCancel_Click()
- End
- End Sub
- Private Sub btnOK_Click()
- If (ValidateField(txtName) = False) Then txtName.SetFocus: Exit Sub
- If (ValidateField(txtCompany) = False) Then txtCompany.SetFocus: Exit Sub
- If (ValidateField(txtAddress) = False) Then txtAddress.SetFocus: Exit Sub
- If (ValidateField(txtAddress2) = False) Then txtAddress2.SetFocus: Exit Sub
- If (ValidateField(txtCityState) = False) Then txtCityState.SetFocus: Exit Sub
- If (ValidateField(txtZipCode) = False) Then txtZipCode.SetFocus: Exit Sub
- If (ValidateField(txtPhone) = False) Then txtPhone.SetFocus: Exit Sub
- If (ValidateField(txtFax) = False) Then txtFax.SetFocus: Exit Sub
- End
- End Sub
- Private Sub Form_Load()
- ' Add controls to the Validate
- ' control's list of controls to watch. This
- ' will cause the Validate event to fire when
- ' the user switches focus from control to
- ' control (later).
- Validate1.AddControl txtName
- Validate1.AddControl txtCompany
- Validate1.AddControl txtAddress
- Validate1.AddControl txtAddress2
- Validate1.AddControl txtCityState
- Validate1.AddControl txtZipCode
- Validate1.AddControl txtPhone
- Validate1.AddControl txtFax
- Validate1.AddControl btnCancel
- Validate1.AddControl VScroll1
- End Sub
- Private Sub HScroll1_Change()
- Debug.Print "hscroll change"
- End Sub
- Private Sub HScroll1_GotFocus()
- Debug.Print "hscroll1 got"
- End Sub
- Private Sub txtName_GotFocus()
- Debug.Print "txtName got"
- End Sub
- ' This subroutine handles data validation
- ' for the form.
- Private Sub Validate1_Validate(ByVal CtrlValidate As Object, ByVal CtrlWantsFocus As Object, Activate As Long)
- ' If the user pressed the Cancel button, don't
- ' bother with any validation.
- '
- ' Note that since the OK button does _not_ get special handling here
- ' the control losing focus will be validated when the OK button is
- ' clicked and this will prevent the OK button from responding to a mouse
- ' click.
- '
- ' In this sample the OK button has the default property set to True
- ' so all fields are validated in the button's click event too since
- ' there is no focus change to trap in this case.
- '
- If CtrlWantsFocus Is btnCancel Then
- Exit Sub
- End If
- ' Allow focus to shift to VScroll1 at any time
- If CtrlWantsFocus Is VScroll1 Then
- Set m_wasValidating = CtrlValidate
- Exit Sub
- End If
- If CtrlValidate Is VScroll1 And Not CtrlWantsFocus Is btnCancel Then
- m_wasValidating.SetFocus
- Activate = False
- Else
- Activate = Not ValidateField(CtrlValidate)
- End If
- End Sub
- Private Function ValidateField(CtrlValidate As Control)
- Dim fOk As Boolean
- fOk = True
- ' How we validate depends on the data.
- Select Case CtrlValidate.Name
- Case "txtName", "txtCompany", "txtAddress", "txtCityState"
- ' In the case of the name and address,
- ' we just want to ensure that we have data.
- If Trim(CtrlValidate.Text) = "" Then
- If CtrlValidate.Name = "txtName" Then
- MsgBox "You must enter a name."
- ElseIf CtrlValidate.Name = "txtCompany" Then
- MsgBox "You must enter a company name"
- ElseIf CtrlValidate.Name = "txtAddress" Then
- MsgBox "You must enter an address."
- Else
- MsgBox "You must enter a city and state."
- End If
- fOk = False
- End If
-
- Case "txtZipCode"
- ' This field requires either a five digit zip code
- ' or a nine digit zip code (with our without hyphen)
- fOk = CheckZipCode(Trim(CtrlValidate.Text))
-
- If Not fOk Then
- MsgBox "'" & Trim(CtrlValidate.Text) & "' is not a valid Zip Code."
- End If
- Case "txtPhone", "txtFax"
- ' These fields expect a phone number in the
- ' form XXX-XXX-XXXX (if anything is present)
- ' This uses the function in VALID.BAS to
- ' determine the phone number's validity.
- If Trim(CtrlValidate.Text) <> "" Then
- fOk = CheckPhoneNumber(Trim(CtrlValidate.Text))
- Else
- fOk = False
- End If
- If Not fOk Then
- MsgBox "'" & Trim(CtrlValidate.Text) & "' is not a valid phone number."
- End If
- End Select
- ValidateField = fOk
- End Function
-